//package tech.cn.note.word.fun;
//
//import java.time.LocalDate;
//import java.util.Arrays;
//import java.util.List;
//
//import com.deepoove.poi.render.compute.RenderDataCompute;
//import org.apache.dubbo.config.annotation.DubboReference;
//import tech.tongyu.bct.common.util.DateTimeUtils;
//import tech.tongyu.bct.reference.calendar.service.TradingCalendarService;
//
//import org.springframework.stereotype.Service;
//
//import static org.springframework.util.ObjectUtils.isEmpty;
//
///**
// * 基于交易日历，2个日期相差的天数
// */
//@Service
//public class TcDaysBetween implements RenderFunction {
//
//    @DubboReference
//    private TradingCalendarService tradingCalendarService;
//
//    /**
//     * @param fields 参数1 开始日期 参数2 结束日期  可选参数 参数3 日历名称数组，参数4 addDay
//     */
//    @Override
//    public String doCalculate(String[] fields, RenderDataCompute renderDataCompute) {
//        if (isEmpty(fields) || fields.length < 2) {
//            return "";
//        }
//        List<String> holidays = null;
//        if (fields.length == 3) {
//            holidays = Arrays.asList(fields[2].split(","));
//        }
//        String dateOne = fields[0];
//        String dateTwo = fields[1];
//        LocalDate startDate = DateTimeUtils.toLocalDate(renderDataCompute.compute(dateOne));
//        LocalDate endDate = DateTimeUtils.toLocalDate(renderDataCompute.compute(dateTwo));
//        if (startDate == null || endDate == null) {
//            return "";
//        }
//        List<LocalDate> businessDays = tradingCalendarService.getBusinessDays(startDate, endDate, holidays);
//
//        int size = businessDays.size();
//        if (fields.length == 4) {
//            int add = Integer.parseInt(fields[3]);
//            size = size + add;
//        }
//        return String.valueOf(size);
//    }
//}
